<template>
  <el-container class="app-container">
    <el-collapse @change="handleCollapseChange" v-model="collapseActiveName">
      <el-collapse-item :title="collapseTitle" name="1">
        <el-tabs type="border-card">
          <el-form :model="pageInfo" ref="form" label-width="130px" size="medium">
            <el-row>
              <el-col :span="5" :offset="0">
                <el-form-item prop="title" label="会议室名称：">
                  <el-input v-model.trim='pageInfo.title' placeholder="请输入名称搜索"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4" :offset="0">
                <el-form-item prop="groupId" label="会议室所属空间:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in spaceOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4" :offset="0">
                <el-form-item prop="groupId" label="支付状态:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in spaceOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="5" :offset="0">
                <el-form-item prop="groupId" label="预定状态:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in zsOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="3" :offset="1">
                <el-button type="primary" icon="el-icon-search" @click='getData'>搜索</el-button>
                <!--                  <el-button @click="resetForm">重置</el-button>-->
              </el-col>
            </el-row>
          </el-form>
        </el-tabs>
      </el-collapse-item>
    </el-collapse>


    <!--表格-->
    <table-view
      :columns="tableContent"
      :pageList="columnData"
      :templateDiv="{operation:true}"
    >
      <template slot="operation" slot-scope="scope">
        <el-button size="mini" ype="primary" @click="editBtnClick(scope.row ,'view')">订单详情</el-button>
      </template>
    </table-view>

    <!--分页-->
    <pagination-view :pagesize="pageInfo.pageSize"
                     :currentPage="pageInfo.pageNumber"
                     :total="total"
                     @size-change="sizeChange"
                     @current-change="pageChange"
    ></pagination-view>


    <el-dialog title="订单详情" :visible.sync="dialogVisible" width="60%"
               :destroy-on-close="true">
      <el-row>
        <el-col :span="10" offset="2">
          <p>订单号：{{}}</p>
          <p>会议室ID：{{}}</p>
          <p>会议室名称：{{}}</p>
          <p>会议室所属空间:{{}}</p>
          <p>下单用户ID：USER20198858849</p>
          <p>预定人:</p>
          <p>联系电话：2345678901</p>
          <p>预定时间段：</p>
          <p>预定时长:</p>
          <p>订单金额:</p>
          <p>优惠折扣:</p>
          <p>实付金额：</p>
        </el-col>
        <el-col :span="8" offset="2">
          <p>下单渠道:</p>
          <p>下单时间：</p>
          <p>预定状态：预定成功</p>
          <p>支付状态：支付成功</p>
          <p>付款方式：微信支付</p>
          <p>付款渠道：空间云助手小程序端</p>
          <p>付款时间： 2020-04-18  08:00:22</p>
          <p>支付流水号： Wxxx039348854ahgh34gagl699236780</p>
          <p>退款时间：</p>
          <p>退款方式：</p>
          <p>退款金额：</p>
          <p>备注：</p>
        </el-col>
      </el-row>
    </el-dialog>
    <el-footer></el-footer>
  </el-container>
</template>

<script>
  import TableView from '@/components/TableView'
  import ImgUpload from '@/components/ImgUpload'

  import PaginationView from '@/components/PaginationView'
  // import pageApi from '@/api/operation/productSetting'

  export default {
    name: 'list',
    components: {
      TableView,
      PaginationView,
      ImgUpload
    },
    data() {
      return {
        spaceOptions:[],
        zsOptions:[{label:'全部',value:''},{label:'可招商',value:'1'},{label:'不可招商',value:'0'}],
        zxOptions:[{label:'全部',value:''},{label:'装修',value:'1'},{label:'简装',value:'2'},{label:'毛坯',value:'3'},{label:'其他',value:'4'}],
        dialogVisible: false,
        tableContent: [{
          field: 'productName',
          label: '订单号'
        }, {
          field: 'productName',
          label: '会议室名称'
        }, {
          field: 'productName',
          label: '预定人'
        }, {
          field: 'productName',
          label: '联系电话'
        }, {
          field: 'productName',
          label: '预定时间段'
        }, {
          field: 'productName',
          label: '预定时长'
        }, {
          field: 'productName',
          label: '订单金额'
        }, {
          field: 'productName',
          label: '优惠抵扣'
        }, {
          field: 'productName',
          label: '实付金额'
        }, {
          field: 'productName',
          label: '预定状态'
        }, {
          field: 'productName',
          label: '下单时间'
        }, {
          field: 'productName',
          label: '备注'
        },{
          field: 'operation',
          label: '操作'
        }],
        columnData: [{}, {}],
        customWidth: '',
        pageInfo: {
          pageNum: 1,
          pageSize: 20,
          title: ''
        },
        total: 0,
      }
    },
    watch: {},
    methods: {
      changeUserStatus: function (id, enable) {
        pageApi.changeEnable(id, enable).then((res) => {
          this.handleMessage(res)
          if (res.code === '200') this.getData()
        })
      },
      onSubmit() {
        let form = this.form
        let dialogType = this.dialogType
        form.duration = form.durationTime + (form.productTypeId == 1 ? '个月' : '天')
        form.enable = Number(form.enable)
        this.$refs['form'].validate((valid) => {
          if (valid) {
            switch (dialogType) {
              case 'add':
                this.dialogTitle = '添加'
                pageApi.create(form).then(res => {
                  this.handleRes(res)
                })
                break
              case 'update':
                this.dialogTitle = '编辑'
                pageApi.update(form).then(res => {
                  this.handleRes(res)
                })
                break
            }
          }
        })
      },
      handleRes(res) {
        this.handleMessage(res)
        if (res.code === '200') {
          this.dialogVisible = false
          this.getData()
        }
      },
      // pageSize变化函数
      sizeChange(val) {
        this.pageInfo.pageSize = val
        this.getData()
      },
      // page变化函数
      pageChange(val) {
        this.pageInfo.pageNumber = val
        this.getData()
      },
      editBtnClick(val, type) {
        switch (type) {
          case 'view':
            pageApi.getById(val.courseProductId).then(res => {
              this.form = Object.assign({}, this.form, res.body)
              let duration = this.form.duration
              let regExp = this.form.productTypeId == 1 ? /个月/ : /天/
              this.form.durationTime = duration.replace(regExp, '')
            })
            this.dialogType = type
            this.dialogVisible = true

            break

        }
      },
      //拉取列表
      getData() {
        pageApi.getList(this.pageInfo).then(res => {
          this.columnData = res.body.records
          this.total = Number(res.body.total)
          this.pageInfo.pageNumber = Number(res.body.pageNumber) || 1
        })
      },
      handleClose(done) {
        let resetForm = {
          costAmount: '',
          courseProductId: '',
          duration: '',
          durationTime: '',
          enable: true,
          intro: '',
          memo: '',
          productName: '',
          saleAmount: '',
          sort: '',
          tag: ''
        }
        this.form = Object.assign({}, this.form, resetForm)
        done()
      }

    },
    mounted() {

      this.getData()
    }
  }
</script>

<style lang="scss" scoped>

</style>
